package com.ht.medicaltreatment.viewmodel

import androidx.lifecycle.viewModelScope
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.ToastUtils
import com.ht.medicaltreatment.bean.PagePD
import com.ht.medicaltreatment.bean.SghyMarshall
import com.xgst.lib.http.ApiResult
import kotlinx.coroutines.launch

class InventoryRecordViewModel : BaseViewModel() {
    fun request(currentPage:String, startTime:String, endTime:String, formName:String?, sampleName:String?,
                onSuccess:(MutableList<PagePD>?)->Unit){
        viewModelScope.launch {
            val bean = mApi.pdRecord(
                currentPage = currentPage,
                endTime = endTime,
                startTime = startTime,
                inventoryTableName = formName?:"",
                sampleName = sampleName?:"",
                pageSize = "20")
            when(bean){
                is ApiResult.Success -> {
                    dismissProgress()
                    onSuccess(bean.data.data?.pageList)
                }
                is ApiResult.Error -> {
                    dismissProgress()
                    ToastUtils.showShort(bean.errorMessage)
                }
            }
        }
    }
}
